package com.tz.actions;

import com.opensymphony.xwork2.ActionSupport;
import com.tz.entity.Category;
import com.tz.service.ProductService;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * Created by Tinyang on 2016/7/23.
 */
@Namespace("/product")
public class CategoryAction extends ActionSupport {
    private List<Category> categoryList;
    @Autowired
    private ProductService productService;
    //ProductBysService1 categoryService= MyAcUtil.getAc().getBean(ProductBysService1.class);


    //public CategoryAction() {
       //Map<String, Object> application = ActionContext.getContext().getApplication();
        //ApplicationContext ac = (ApplicationContext) application.get("ac");
       //System.out.println("我们来看一下ac内存地址:" + ac);
        //this.categoryService = ac.getBean(ProductBysService1.class);
    //}

    @Action(value="category",results = {
            @Result(name =SUCCESS,location = "/index.jsp")
    })
    public String selectCategory(){
        categoryList=productService.getAllCategories();
        return SUCCESS;
    }

    public List<Category> getCategoryList() {
        return categoryList;
    }

    public void setCategoryList(List<Category> categoryList) {
        this.categoryList = categoryList;
    }
}
